package cloud.lysky.java.on.concurrent.thread;

/**
 * @author luoly
 * @describe
 * @date 2022-10-18 18:31
 **/
public class ThreadJoinDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Thread A begin");
                try {
                    Thread.sleep(5000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                    System.out.println("Thread A finished");
                }
            }
        });

        long start = System.currentTimeMillis();
        thread.start();
        //让主线程等待线程threadA执行完成
        thread.join();
        System.out.println("cost time:" + (System.currentTimeMillis() - start));
        System.out.println("Main finished");
    }
}